package com.itlaobing.demo.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @Classname FileServlet
 * @Description TODO()
 * @Date 2020/11/10 0010 17:49
 * @Author by Administrator
 * @Version v1.0
 */
@WebServlet("/file")
public class FileServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取
        String name = req.getParameter("name");
        String localPath = "D://temp//header";
        File file = new File(localPath , name);
        FileInputStream in = new FileInputStream(file);

        OutputStream out = resp.getOutputStream();
        byte[] bytes = new byte[1024];
        int len = 0;
        while((len = in.read(bytes)) != -1){
            out.write(bytes, 0, len);
        }
    }
}
